
#
# def page(request):
#     list = [{'user': '时光{}'.format(i), 'password': 'shiguang{}'.format(i)} for i in range(1, 1000)]
#     num = 20  # 一页展示20行数据
#     nums = 11  # 分页显示个数
#     try:
#         page = int(request.GET.get('page', '1'))  # 获取传过来的页数，获取不到默认为1
#     except Exception:
#         page = 1
#     if page <= 0:
#         page = 1
#     amount, mod = divmod(len(list), num)  # 计算分页数量，有余数加1
#     if mod:
#         amount += 1
#     page_start = (page - 1) * num
#     page_end = page * num
#     amount_start = page - (nums - 1) // 2  # 页数显示的起始数
#     amount_end = page + (nums - 1) // 2  # 页数显示的末尾数
#     # 进行判断前面是否有足够的数据
#     if amount_start <= 0:
#         amount_start = 1
#         amount_end = nums
#     # 进行判断后面是否有足够的数据
#     elif amount_end >= amount:
#         amount_start = amount - nums
#         amount_end = amount
#
#     return render(request, 'page.html',
#                   {'list': list[page_start:page_end], 'amount': [i for i in range(amount_start, amount_end + 1)],
#                    'page': page, 'pagep': page - 1, 'pagen': page + 1, 'count': amount})